'''
Created on 03-Apr-2010

@author: darsh
'''

import os
IMAGEPATH=os.path.expanduser(os.path.join("~", ".glassbead", "images"))

from PyQt4 import QtCore,QtGui,Qt
import sys


class FrameWidget(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        #maximizeicon=QtGui.QIcon(os.path.join("minimize.jpeg"))
        #maximizebitmap=QtGui.QBitmap(maximizeicon)
        self.closebutton=QtGui.QPushButton("x")
        self.closebutton.setFixedSize(32,32)
        self.maximizebutton=QtGui.QPushButton("m")
        self.maximizebutton.setFixedSize(32,32)
        #self.maximizebutton.setIcon(maximizeicon)
        #self.maximizebutton.setIconSize(QtCore.QSize(32,32))
        #self.maximizebutton.setMask(maximizebitmap)
        #self.maximizebutton.setGeometry()
        self.minimizebutton=QtGui.QPushButton("-")
        self.minimizebutton.setFixedSize(32,32)
        self.MainLayout=QtGui.QHBoxLayout()
        self.MainLayout.setMargin(0)
        self.MainLayout.setAlignment(Qt.Qt.AlignRight)
        self.MainLayout.addWidget(self.maximizebutton)
        self.MainLayout.addWidget(self.minimizebutton)
        self.MainLayout.addWidget(self.closebutton)
        self.setLayout(self.MainLayout)
        self.dragstartX=0
        self.dragstartY=0
        self.dragstopX=0
        self.dragstopY=0
        #self.setWindowOpacity(0.81)
        QtCore.QObject.connect(self.closebutton,QtCore.SIGNAL("clicked()"),self.handleclose)
        QtCore.QObject.connect(self.maximizebutton,QtCore.SIGNAL("clicked()"),self.handlemaximize)
        QtCore.QObject.connect(self.minimizebutton,QtCore.SIGNAL("clicked()"),self.handleminimize)
        QtCore.QMetaObject.connectSlotsByName(self)
        
    def handleclose(self):
        self.emit(QtCore.SIGNAL("closed()"))
        self.close()
        
    def mousePressEvent(self,event):
        self.dragstartX=event.globalX()
        self.dragstartY=event.globalY()
        
    def mouseReleaseEvent(self,event):
        self.dragstopX=event.globalX()
        self.dragstopY=event.globalY()
        xdisplacement=self.dragstopX-self.dragstartX
        ydisplacement=self.dragstopY-self.dragstartY
        oldx=self.framedwindow.x
        oldy=self.framedwindow.y
        self.framedwindow.place(oldx+xdisplacement,oldy+ydisplacement,self.framedwindow.width,self.framedwindow.height,1,None)
    
    def handlemaximize(self):
        self.emit(QtCore.SIGNAL("maximized()"))
        
    def handleminimize(self):
        self.emit(QtCore.SIGNAL("minimized()"))
        
    
if __name__=="__main__":
    app=QtGui.QApplication(sys.argv)    
    #opeffect=QtGui.QGraphicsBlurEffect()
    Form = FrameWidget()
    #Form.resize(1040,840)
    Form.setWindowTitle("VerbDesk")
    #Form.setWindowOpacity(0.86)
    #Form.setFixedSize(640,480)
    # Form.setWindowOpacity(0.7)
    #ui = VerbsListWidget()
    #ui.setupUi(Form)
    #Form.setEffect(opeffect)
    #view.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
    #view.setAttribute(Qt.Qt.WA_TranslucentBackground, True)
    #view.show()
    Form.show()
    #Form.fireverb()
    #  Form.fireverb()
    sys.exit(app.exec_())